Home docs nex NEX common types
Post

NEX common types

String

TypeDescription
Uint16Length (including null terminator)
CharsNull terminated UTF-8 string

Buffer

TypeDescription
Uint32Length
BytesData

qBuffer

TypeDescription
Uint16Length
BytesData

List

TypeDescription
Uint32Number of entries
 Entries

Map

A map is a list of (key, value) pairs.

PID

Every user is given a unique id called principal id.

PlatformType
3DS / Wii UUint32
SwitchUint64

Result

TypeDescription
Uint32Result code

If the most significant bit is set an error occurred. Otherwise, the result indicates success. A list of error codes can be found in nintendo/nex/errors.py.

DateTime

TypeDescription
Uint64Value

This is not a normal time stamp. Instead, it consists of a bunch of bit fields:

BitsDescription
63 - 26Year
25 - 22Month
21 - 17Day
16 - 12Hour
11 - 6Minute
5 - 0Second

StationURL

TypeDescription
StringStation URL

A station url contains the address and port of a server or client, along with a few parameters. The order of the fields is arbitrary. Here’s an example station url: prudps:/stream=10;sid=1;CID=1;type=2;address=34.210.222.104;port=60101;PID=2

FieldDescription
<scheme>udp, prudp or prudps
addressAddress
portPort
streamStream type (see here)
sidStream id (PRUDP port)
CIDConnection id
PIDPrincipal id
typeNAT type flags
RVCIDRendez-vous connection id
natmNAT mapping
natfNAT filtering
upnpUPnP support (0 or 1)
pmpPMP support (0 or 1)
probeinitProbe request initiation
PRIDProbe request id
fastproberesponseFast probe response
NodeIDNode id

The following fields were added on Nintendo Switch:

FieldDescription
UriUri
RUse relay server (0 or 1)
RsaRelay server address
RspRelay server port
RaRelay address
RpRelay port
TptTransport protocol type
PlPlatform type
NtrpaNAT traversal requester private address
NtrppNAT traversal requester private port

NAT Type Flags

FlagDescription
1Is behind NAT
2Is public

NAT Mapping

ValueDescription
0Unknown
1Endpoint independent mapping
2Endpoint dependent mapping

NAT Filtering

ValueDescription
0Unknown
1Port independent filtering
2Port dependent filtering

Variant

A variant consists of an uint8 indicating the type followed by its value.

Type idType
0None
1Sint64
2Double
3Bool
4String
5DateTime
6Uint64

Structure

When using the “verbose” RMC variation the structure version information is stored in the ClassVersionContainer. When using the “packed” RMC variation, and the client is using NEX v3.5.0 or above, the structures version information is encoded as a header before the structures contents. Before NEX v3.5.0, the structures contents are encoded directly into the stream without a version header

Structure header

TypeDescription
Uint8Version
Uint32Content length
 Content

Nintendo often seems to be changing a structure without updating its version number though.

Structure Inheritance

A structure may inherit another structure. The child is stored right after the parent, and gets its own version header.

Example: If there are 2 structures, StructureA and StructureB, with StructureB inheriting from StructureA, the data would be stored as follows:

  • StructureA Structure Header (if any)
  • StructureA Structure data (if any)
  • StructureB Structure Header (if any)
  • StructureB Structure data (if any)

Data (Structure)

This struct does not have any fields.

AnyDataHolder

This class can hold any object derived from a given base class (usually nn::nex::Data). Some meta data is sent along with it, so the other side can properly identify and decode the object.

TypeDescription
StringType name
Uint32Length of data, including the next length field
Uint32Length of data
 Object data

RVConnectionData (Structure)

Nintendo does not use any special protocols.

TypeNameDescription
StationURLm_urlRegularProtocolsServer address (regular protocols)
List<byte>m_lstSpecialProtocolsSpecial protocols
StationURLm_urlSpecialProtocolsServer address (special protocols)

Revision 1:

TypeNameDescription
DateTimem_currentUTCTimeTime

Examples:

GameSecure server
Friendsprudps:/stream=10;type=2;PID=2;port=60091;address=35.162.205.114;sid=1;CID=1
DKC:TFprudps:/port=43221;CID=1;address=34.208.166.202;PID=2;stream=10;type=2;sid=1
MK8prudps:/sid=1;port=59201;address=52.10.188.163;PID=2;stream=10;type=2;CID=1

ResultRange (Structure)

Some methods query a large set of objects. These methods normally take a ResultRange parameter that limits the number of objects that are returned.

TypeNameDescription
Uint32m_uiOffsetOffset
Uint32m_uiSizeLength

qUUID

A qUUID is a set of 16 bytes making up a UUID. These are usually UUIDv4 variant 8, but this is not required. The data is split into 7 little endian fields, the first 4 being the first 4 sections of the UUID with the 5th section being made of the remaining 3 fields. To convert to a UUID string, swap the endianness of each field back to big endian

TypeDescription
Bytes (4)Section 1
Bytes (2)Section 2
Bytes (2)Section 3
Bytes (2)Section 4
Bytes (2)Section 5 part 1
Bytes (2)Section 5 part 2
Bytes (2)Section 5 part 3

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
uuid = bytes.fromhex("ae5e3e66297d8c4aa98420499ad98c3e")

section1 = uuid[0:4][::-1].hex()
section2 = uuid[4:6][::-1].hex()
section3 = uuid[6:8][::-1].hex()
section4 = uuid[8:10][::-1].hex()
section5_1 = uuid[10:12][::-1].hex()
section5_2 = uuid[12:14][::-1].hex()
section5_3 = uuid[14:16][::-1].hex()

expected = "663e5eae-7d29-4a8c-84a9-4920d99a3e8c"

"""
Prints:

663e5eae-7d29-4a8c-84a9-4920d99a3e8c
663e5eae-7d29-4a8c-84a9-4920d99a3e8c
"""

print(expected)
print("%s-%s-%s-%s-%s%s%s" % (section1, section2, section3, section4, section5_1, section5_2, section5_3))
Contents