Binary Reading in C#

Yoshifumi Kawai
Yoshifumi KawaiCTO at Cysharp
Binary Reading in C#
https://github.com/neuecc/Messag
ePack-CSharp/
Int32 Read(byte[] bytes, int offset)
{
return (bytes[offset + 0] << 24)
| (bytes[offset + 1] << 16)
| (bytes[offset + 2] << 8)
| (bytes[offset + 3]);
}
Int32 Read(byte[] bytes, int offset)
{
return (bytes[offset + 0])
| (bytes[offset + 1] << 8)
| (bytes[offset + 2] << 16)
| (bytes[offset + 3] << 24);
}
unsafe int ReadInt32(byte[] bytes, int
offset)
{
fixed (byte* ptr = bytes)
{
return *(int*)(ptr + offset);
}
}
[StructLayout(LayoutKind.Explicit)]
internal struct Float32Bits
{
[FieldOffset(0)]
public float Value;
[FieldOffset(0)]
public Byte Byte0;
[FieldOffset(1)]
public Byte Byte1;
[FieldOffset(2)]
public Byte Byte2;
[FieldOffset(3)]
public Byte Byte3;
}
https://github.com/msgpack/msgpack/blob/master/spec.md
public MessagepackType ReadMessagePackType(byte[] bytes, int offset)
{
var code = bytes[offset];
if (0 <= code && code <= MessagePackRange.MaxFixPositiveInt)
{
return FixInt;
}
if (MessagePackRange.MinFixNegativeInt <= code)
{
return NegativeInt;
}
switch (code)
{
case Int8:
return Int8;
case Int16:
return Int16;
case Int32:
return Int32;
// 以下略
}
static readonly MessagePackType[] typeLookupTable = new MessagePackType[256];
static MessagePackCode()
{
for (int i = MinFixInt; i <= MaxFixInt; i++)
{
typeLookupTable[i] = MessagePackType.Integer;
}
for (int i = MinFixMap; i <= MaxFixMap; i++)
{
typeLookupTable[i] = MessagePackType.Map;
}
typeLookupTable[Nil] = MessagePackType.Nil;
typeLookupTable[False] = MessagePackType.Boolean;
typeLookupTable[True] = MessagePackType.Boolean;
typeLookupTable[Bin8] = MessagePackType.Binary;
typeLookupTable[Bin16] = MessagePackType.Binary;
// 以下略....
}
static readonly IMapHeaderDecoder[] mapHeaderDecoders = new IMapHeaderDecoder[MaxSize];
static readonly IArrayHeaderDecoder[] arrayHeaderDecoders = new IArrayHeaderDecoder[MaxSize];
static readonly IBooleanDecoder[] booleanDecoders = new IBooleanDecoder[MaxSize];
static readonly IByteDecoder[] byteDecoders = new IByteDecoder[MaxSize];
static readonly IBytesDecoder[] bytesDecoders = new IBytesDecoder[MaxSize];
static readonly ISByteDecoder[] sbyteDecoders = new ISByteDecoder[MaxSize];
static readonly ISingleDecoder[] singleDecoders = new ISingleDecoder[MaxSize];
static readonly IDoubleDecoder[] doubleDecoders = new IDoubleDecoder[MaxSize];
static readonly IInt16Decoder[] int16Decoders = new IInt16Decoder[MaxSize];
static readonly IInt32Decoder[] int32Decoders = new IInt32Decoder[MaxSize];
static readonly IInt64Decoder[] int64Decoders = new IInt64Decoder[MaxSize];
static readonly IUInt16Decoder[] uint16Decoders = new IUInt16Decoder[MaxSize];
static readonly IUInt32Decoder[] uint32Decoders = new IUInt32Decoder[MaxSize];
static readonly IUInt64Decoder[] uint64Decoders = new IUInt64Decoder[MaxSize];
static readonly IStringDecoder[] stringDecoders = new IStringDecoder[MaxSize];
static readonly IExtDecoder[] extDecoders = new IExtDecoder[MaxSize];
static readonly IExtHeaderDecoder[] extHeaderDecoders = new IExtHeaderDecoder[MaxSize];
static readonly IDateTimeDecoder[] dateTimeDecoders = new IDateTimeDecoder[MaxSize];
static readonly IReadNextDecoder[] readNextDecoders = new IReadNextDecoder[MaxSize];
static readonly IMapHeaderDecoder[] mapHeaderDecoders = new IMapHeaderDecoder[MaxSize];
static readonly IArrayHeaderDecoder[] arrayHeaderDecoders = new IArrayHeaderDecoder[MaxSize];
static readonly IBooleanDecoder[] booleanDecoders = new IBooleanDecoder[MaxSize];
static readonly IByteDecoder[] byteDecoders = new IByteDecoder[MaxSize];
static readonly IBytesDecoder[] bytesDecoders = new IBytesDecoder[MaxSize];
static readonly ISByteDecoder[] sbyteDecoders = new ISByteDecoder[MaxSize];
static readonly ISingleDecoder[] singleDecoders = new ISingleDecoder[MaxSize];
static readonly IDoubleDecoder[] doubleDecoders = new IDoubleDecoder[MaxSize];
static readonly IInt16Decoder[] int16Decoders = new IInt16Decoder[MaxSize];
static readonly IInt32Decoder[] int32Decoders = new IInt32Decoder[MaxSize];
static readonly IInt64Decoder[] int64Decoders = new IInt64Decoder[MaxSize];
static readonly IUInt16Decoder[] uint16Decoders = new IUInt16Decoder[MaxSize];
static readonly IUInt32Decoder[] uint32Decoders = new IUInt32Decoder[MaxSize];
static readonly IUInt64Decoder[] uint64Decoders = new IUInt64Decoder[MaxSize];
static readonly IStringDecoder[] stringDecoders = new IStringDecoder[MaxSize];
static readonly IExtDecoder[] extDecoders = new IExtDecoder[MaxSize];
static readonly IExtHeaderDecoder[] extHeaderDecoders = new IExtHeaderDecoder[MaxSize];
static readonly IDateTimeDecoder[] dateTimeDecoders = new IDateTimeDecoder[MaxSize];
static readonly IReadNextDecoder[] readNextDecoders = new IReadNextDecoder[MaxSize];
internal interface IInt32Decoder
{
Int32 Read(byte[] bytes, int offset, out int readSize);
}
デリゲートは楽
が、Fastestではない
void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
byte[] WriteVector3(Vector3[] collection)
{
var bytes = new byte[collection.Length * 12];
foreach (var item in collection)
{
WriteFloat(bytes, item.x);
WriteFloat(bytes, item.y);
WriteFloat(bytes, item.z);
}
return bytes;
}
Binary Reading in C#
public static unsafe void SimpleMemoryCopy(void* dest, void* src, int byteCount)
{
var pDest = (byte*)dest;
var pSrc = (byte*)src;
for (int i = 0; i < byteCount; i++)
{
*pDest = *pSrc;
pDest++;
pSrc++;
}
}
Vector3[]を一応Unityネイティブの
JsonUtilityの50倍高速にコピー可能
MessagePackの仕様内を逸脱しないよ
うに、Extension Formatを先頭識別子
に埋め込むことで互換性を保ちつつ
高速化
1 of 15

Recommended

Xz file-format-1.0.4 by
Xz file-format-1.0.4Xz file-format-1.0.4
Xz file-format-1.0.4Ben Pope
249 views18 slides
「黒騎士と白の魔王」gRPCによるHTTP/2 - API, Streamingの実践 by
「黒騎士と白の魔王」gRPCによるHTTP/2 - API, Streamingの実践「黒騎士と白の魔王」gRPCによるHTTP/2 - API, Streamingの実践
「黒騎士と白の魔王」gRPCによるHTTP/2 - API, Streamingの実践Yoshifumi Kawai
253.5K views53 slides
HttpClient詳解、或いは非同期の落とし穴について by
HttpClient詳解、或いは非同期の落とし穴についてHttpClient詳解、或いは非同期の落とし穴について
HttpClient詳解、或いは非同期の落とし穴についてYoshifumi Kawai
90.5K views37 slides
【Unite 2017 Tokyo】「黒騎士と白の魔王」にみるC#で統一したサーバー/クライアント開発と現実的なUniRx使いこなし術 by
【Unite 2017 Tokyo】「黒騎士と白の魔王」にみるC#で統一したサーバー/クライアント開発と現実的なUniRx使いこなし術【Unite 2017 Tokyo】「黒騎士と白の魔王」にみるC#で統一したサーバー/クライアント開発と現実的なUniRx使いこなし術
【Unite 2017 Tokyo】「黒騎士と白の魔王」にみるC#で統一したサーバー/クライアント開発と現実的なUniRx使いこなし術Unity Technologies Japan K.K.
186K views89 slides
RuntimeUnitTestToolkit for Unity by
RuntimeUnitTestToolkit for UnityRuntimeUnitTestToolkit for Unity
RuntimeUnitTestToolkit for UnityYoshifumi Kawai
70.2K views17 slides
ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法 by
ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法
ZeroFormatterに見るC#で最速のシリアライザを作成する100億の方法Yoshifumi Kawai
54.1K views27 slides

More Related Content

Viewers also liked

LINQ in Unity by
LINQ in UnityLINQ in Unity
LINQ in UnityYoshifumi Kawai
50.6K views39 slides
ZeroFormatter/MagicOnion - Fastest C# Serializer/gRPC based C# RPC by
ZeroFormatter/MagicOnion - Fastest C# Serializer/gRPC based C# RPCZeroFormatter/MagicOnion - Fastest C# Serializer/gRPC based C# RPC
ZeroFormatter/MagicOnion - Fastest C# Serializer/gRPC based C# RPCYoshifumi Kawai
48.7K views31 slides
UniRx - Reactive Extensions for Unity by
UniRx - Reactive Extensions for UnityUniRx - Reactive Extensions for Unity
UniRx - Reactive Extensions for UnityYoshifumi Kawai
68.7K views31 slides
What, Why, How Create OSS Libraries - 過去に制作した30のライブラリから見るC#コーディングテクニックと個人OSSの... by
What, Why, How Create OSS Libraries - 過去に制作した30のライブラリから見るC#コーディングテクニックと個人OSSの...What, Why, How Create OSS Libraries - 過去に制作した30のライブラリから見るC#コーディングテクニックと個人OSSの...
What, Why, How Create OSS Libraries - 過去に制作した30のライブラリから見るC#コーディングテクニックと個人OSSの...Yoshifumi Kawai
56.5K views68 slides
Metaprogramming Universe in C# - 実例に見るILからRoslynまでの活用例 by
Metaprogramming Universe in C# - 実例に見るILからRoslynまでの活用例Metaprogramming Universe in C# - 実例に見るILからRoslynまでの活用例
Metaprogramming Universe in C# - 実例に見るILからRoslynまでの活用例Yoshifumi Kawai
125.1K views42 slides
Unity に於けるモバイルプラットフォーム向けビルド自動化のおはなし by
Unity に於けるモバイルプラットフォーム向けビルド自動化のおはなしUnity に於けるモバイルプラットフォーム向けビルド自動化のおはなし
Unity に於けるモバイルプラットフォーム向けビルド自動化のおはなしMori Tetsuya
6.6K views40 slides

Viewers also liked(20)

ZeroFormatter/MagicOnion - Fastest C# Serializer/gRPC based C# RPC by Yoshifumi Kawai
ZeroFormatter/MagicOnion - Fastest C# Serializer/gRPC based C# RPCZeroFormatter/MagicOnion - Fastest C# Serializer/gRPC based C# RPC
ZeroFormatter/MagicOnion - Fastest C# Serializer/gRPC based C# RPC
Yoshifumi Kawai48.7K views
UniRx - Reactive Extensions for Unity by Yoshifumi Kawai
UniRx - Reactive Extensions for UnityUniRx - Reactive Extensions for Unity
UniRx - Reactive Extensions for Unity
Yoshifumi Kawai68.7K views
What, Why, How Create OSS Libraries - 過去に制作した30のライブラリから見るC#コーディングテクニックと個人OSSの... by Yoshifumi Kawai
What, Why, How Create OSS Libraries - 過去に制作した30のライブラリから見るC#コーディングテクニックと個人OSSの...What, Why, How Create OSS Libraries - 過去に制作した30のライブラリから見るC#コーディングテクニックと個人OSSの...
What, Why, How Create OSS Libraries - 過去に制作した30のライブラリから見るC#コーディングテクニックと個人OSSの...
Yoshifumi Kawai56.5K views
Metaprogramming Universe in C# - 実例に見るILからRoslynまでの活用例 by Yoshifumi Kawai
Metaprogramming Universe in C# - 実例に見るILからRoslynまでの活用例Metaprogramming Universe in C# - 実例に見るILからRoslynまでの活用例
Metaprogramming Universe in C# - 実例に見るILからRoslynまでの活用例
Yoshifumi Kawai125.1K views
Unity に於けるモバイルプラットフォーム向けビルド自動化のおはなし by Mori Tetsuya
Unity に於けるモバイルプラットフォーム向けビルド自動化のおはなしUnity に於けるモバイルプラットフォーム向けビルド自動化のおはなし
Unity に於けるモバイルプラットフォーム向けビルド自動化のおはなし
Mori Tetsuya6.6K views
Unityでlinqを使おう by Yuuki Takada
Unityでlinqを使おうUnityでlinqを使おう
Unityでlinqを使おう
Yuuki Takada3.2K views
良くわかるMeta by daichi horio
良くわかるMeta良くわかるMeta
良くわかるMeta
daichi horio34.4K views
Gtmf2011 2011.06.07 slideshare by Hiroki Omae
Gtmf2011 2011.06.07 slideshareGtmf2011 2011.06.07 slideshare
Gtmf2011 2011.06.07 slideshare
Hiroki Omae8.3K views
Unityと.NET by AimingStudy
Unityと.NETUnityと.NET
Unityと.NET
AimingStudy18.1K views
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう by Unity Technologies Japan K.K.
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
4 Colors Othello’s Algorithm @仙台 IT 文化祭 2017 by Takaaki Suzuki
4 Colors Othello’s Algorithm @仙台 IT 文化祭 20174 Colors Othello’s Algorithm @仙台 IT 文化祭 2017
4 Colors Othello’s Algorithm @仙台 IT 文化祭 2017
Takaaki Suzuki3.8K views
How to Make Own Framework built on OWIN by Yoshifumi Kawai
How to Make Own Framework built on OWINHow to Make Own Framework built on OWIN
How to Make Own Framework built on OWIN
Yoshifumi Kawai38.1K views
【Unite 2017 Tokyo】VRで探り,活用する,人の知覚の仕組み by Unite2017Tokyo
【Unite 2017 Tokyo】VRで探り,活用する,人の知覚の仕組み【Unite 2017 Tokyo】VRで探り,活用する,人の知覚の仕組み
【Unite 2017 Tokyo】VRで探り,活用する,人の知覚の仕組み
Unite2017Tokyo10.7K views
.NET の今と未来 ~ デバイス&クラウド ネイティブを目指して by Akira Inoue
.NET の今と未来 ~ デバイス&クラウド ネイティブを目指して.NET の今と未来 ~ デバイス&クラウド ネイティブを目指して
.NET の今と未来 ~ デバイス&クラウド ネイティブを目指して
Akira Inoue2.6K views
【Unite 2017 Tokyo】もっと気軽に、動的なコンテンツ配信を ~アセットバンドルの未来と開発ロードマップ by Unite2017Tokyo
【Unite 2017 Tokyo】もっと気軽に、動的なコンテンツ配信を ~アセットバンドルの未来と開発ロードマップ【Unite 2017 Tokyo】もっと気軽に、動的なコンテンツ配信を ~アセットバンドルの未来と開発ロードマップ
【Unite 2017 Tokyo】もっと気軽に、動的なコンテンツ配信を ~アセットバンドルの未来と開発ロードマップ
Unite2017Tokyo6.4K views
async/await不要論 by bleis tift
async/await不要論async/await不要論
async/await不要論
bleis tift29K views
【Unite 2017 Tokyo】セルシェーダーを使用した3Dキャラアプリの開発事例 by Unity Technologies Japan K.K.
【Unite 2017 Tokyo】セルシェーダーを使用した3Dキャラアプリの開発事例【Unite 2017 Tokyo】セルシェーダーを使用した3Dキャラアプリの開発事例
【Unite 2017 Tokyo】セルシェーダーを使用した3Dキャラアプリの開発事例
LINQPad with LINQ to BigQuery - Desktop Client for BigQuery by Yoshifumi Kawai
LINQPad with LINQ to BigQuery - Desktop Client for BigQueryLINQPad with LINQ to BigQuery - Desktop Client for BigQuery
LINQPad with LINQ to BigQuery - Desktop Client for BigQuery
Yoshifumi Kawai5.2K views
How to make the Fastest C# Serializer, In the case of ZeroFormatter by Yoshifumi Kawai
How to make the Fastest C# Serializer, In the case of ZeroFormatterHow to make the Fastest C# Serializer, In the case of ZeroFormatter
How to make the Fastest C# Serializer, In the case of ZeroFormatter
Yoshifumi Kawai8K views

Similar to Binary Reading in C#

Ac2 by
Ac2Ac2
Ac2Muhammad Islahuddin
128 views13 slides
C++ Code as Seen by a Hypercritical Reviewer by
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerAndrey Karpov
143 views148 slides
Java binary subtraction by
Java binary subtractionJava binary subtraction
Java binary subtractionCharm Sasi
525 views2 slides
A scrupulous code review - 15 bugs in C++ code by
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codePVS-Studio LLC
73 views133 slides
The Art of Clean Code by
The Art of Clean CodeThe Art of Clean Code
The Art of Clean CodeYael Zaritsky Perez
104 views78 slides
Some examples of the 64-bit code errors by
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errorsPVS-Studio
311 views22 slides

Similar to Binary Reading in C#(20)

C++ Code as Seen by a Hypercritical Reviewer by Andrey Karpov
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
Andrey Karpov143 views
Java binary subtraction by Charm Sasi
Java binary subtractionJava binary subtraction
Java binary subtraction
Charm Sasi525 views
A scrupulous code review - 15 bugs in C++ code by PVS-Studio LLC
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
PVS-Studio LLC73 views
Some examples of the 64-bit code errors by PVS-Studio
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errors
PVS-Studio311 views
Getting started cpp full by Võ Hòa
Getting started cpp   fullGetting started cpp   full
Getting started cpp full
Võ Hòa491 views
Lo Mejor Del Pdc2008 El Futrode C# by Juan Pablo
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
Juan Pablo 412 views
The one that was previously posted on here does not compile or functio.pdf by astarmobiles
The one that was previously posted on here does not compile or functio.pdfThe one that was previously posted on here does not compile or functio.pdf
The one that was previously posted on here does not compile or functio.pdf
astarmobiles2 views
These are the things I have to do to the code please help me out- Chan.pdf by DylanTZEAverys
These are the things I have to do to the code please help me out- Chan.pdfThese are the things I have to do to the code please help me out- Chan.pdf
These are the things I have to do to the code please help me out- Chan.pdf
DylanTZEAverys3 views
Deep dumpster diving 2010 by RonnBlack
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010
RonnBlack423 views
Intel JIT Talk by iamdvander
Intel JIT TalkIntel JIT Talk
Intel JIT Talk
iamdvander1.6K views
Python Programming: Lists, Modules, Exceptions by Sreedhar Chowdam
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
Sreedhar Chowdam716 views
COSCUP2023 RSA256 Verilator.pdf by Yodalee
COSCUP2023 RSA256 Verilator.pdfCOSCUP2023 RSA256 Verilator.pdf
COSCUP2023 RSA256 Verilator.pdf
Yodalee228 views
Python 내장 함수 by 용 최
Python 내장 함수Python 내장 함수
Python 내장 함수
용 최2.4K views
1- (25 pts) Implement the insert method for binary search trees- Do no.pdf by AdrianEBJKingr
1- (25 pts) Implement the insert method for binary search trees- Do no.pdf1- (25 pts) Implement the insert method for binary search trees- Do no.pdf
1- (25 pts) Implement the insert method for binary search trees- Do no.pdf
AdrianEBJKingr3 views
Java Simple Programs by Upender Upr
Java Simple ProgramsJava Simple Programs
Java Simple Programs
Upender Upr6.2K views

More from Yoshifumi Kawai

A quick tour of the Cysharp OSS by
A quick tour of the Cysharp OSSA quick tour of the Cysharp OSS
A quick tour of the Cysharp OSSYoshifumi Kawai
60.3K views20 slides
A Brief History of UniRx/UniTask, IUniTaskSource in Depth by
A Brief History of UniRx/UniTask, IUniTaskSource in DepthA Brief History of UniRx/UniTask, IUniTaskSource in Depth
A Brief History of UniRx/UniTask, IUniTaskSource in DepthYoshifumi Kawai
1.9K views19 slides
Building the Game Server both API and Realtime via c# by
Building the Game Server both API and Realtime via c#Building the Game Server both API and Realtime via c#
Building the Game Server both API and Realtime via c#Yoshifumi Kawai
53.8K views67 slides
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能 by
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能Yoshifumi Kawai
42.8K views44 slides
Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現 by
Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現
Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現Yoshifumi Kawai
4.8K views52 slides
Unity C#と.NET Core(MagicOnion) C# そしてKotlinによるハーモニー by
Unity C#と.NET Core(MagicOnion) C# そしてKotlinによるハーモニーUnity C#と.NET Core(MagicOnion) C# そしてKotlinによるハーモニー
Unity C#と.NET Core(MagicOnion) C# そしてKotlinによるハーモニーYoshifumi Kawai
42.9K views37 slides

More from Yoshifumi Kawai(20)

A quick tour of the Cysharp OSS by Yoshifumi Kawai
A quick tour of the Cysharp OSSA quick tour of the Cysharp OSS
A quick tour of the Cysharp OSS
Yoshifumi Kawai60.3K views
A Brief History of UniRx/UniTask, IUniTaskSource in Depth by Yoshifumi Kawai
A Brief History of UniRx/UniTask, IUniTaskSource in DepthA Brief History of UniRx/UniTask, IUniTaskSource in Depth
A Brief History of UniRx/UniTask, IUniTaskSource in Depth
Yoshifumi Kawai1.9K views
Building the Game Server both API and Realtime via c# by Yoshifumi Kawai
Building the Game Server both API and Realtime via c#Building the Game Server both API and Realtime via c#
Building the Game Server both API and Realtime via c#
Yoshifumi Kawai53.8K views
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能 by Yoshifumi Kawai
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能
Yoshifumi Kawai42.8K views
Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現 by Yoshifumi Kawai
Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現
Unityによるリアルタイム通信とMagicOnionによるC#大統一理論の実現
Yoshifumi Kawai4.8K views
Unity C#と.NET Core(MagicOnion) C# そしてKotlinによるハーモニー by Yoshifumi Kawai
Unity C#と.NET Core(MagicOnion) C# そしてKotlinによるハーモニーUnity C#と.NET Core(MagicOnion) C# そしてKotlinによるハーモニー
Unity C#と.NET Core(MagicOnion) C# そしてKotlinによるハーモニー
Yoshifumi Kawai42.9K views
Implements OpenTelemetry Collector in DotNet by Yoshifumi Kawai
Implements OpenTelemetry Collector in DotNetImplements OpenTelemetry Collector in DotNet
Implements OpenTelemetry Collector in DotNet
Yoshifumi Kawai42.6K views
Deep Dive async/await in Unity with UniTask(EN) by Yoshifumi Kawai
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)
Yoshifumi Kawai36.4K views
The Usage and Patterns of MagicOnion by Yoshifumi Kawai
The Usage and Patterns of MagicOnionThe Usage and Patterns of MagicOnion
The Usage and Patterns of MagicOnion
Yoshifumi Kawai46.9K views
True Cloud Native Batch Workflow for .NET with MicroBatchFramework by Yoshifumi Kawai
True Cloud Native Batch Workflow for .NET with MicroBatchFrameworkTrue Cloud Native Batch Workflow for .NET with MicroBatchFramework
True Cloud Native Batch Workflow for .NET with MicroBatchFramework
Yoshifumi Kawai33.1K views
Memory Management of C# with Unity Native Collections by Yoshifumi Kawai
Memory Management of C# with Unity Native CollectionsMemory Management of C# with Unity Native Collections
Memory Management of C# with Unity Native Collections
Yoshifumi Kawai64.6K views
Deep Dive async/await in Unity with UniTask(UniRx.Async) by Yoshifumi Kawai
Deep Dive async/await in Unity with UniTask(UniRx.Async)Deep Dive async/await in Unity with UniTask(UniRx.Async)
Deep Dive async/await in Unity with UniTask(UniRx.Async)
Yoshifumi Kawai105.6K views
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する by Yoshifumi Kawai
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭するCEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
Yoshifumi Kawai74.7K views
RuntimeUnitTestToolkit for Unity(English) by Yoshifumi Kawai
RuntimeUnitTestToolkit for Unity(English)RuntimeUnitTestToolkit for Unity(English)
RuntimeUnitTestToolkit for Unity(English)
Yoshifumi Kawai17.5K views
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ... by Yoshifumi Kawai
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Yoshifumi Kawai4.6K views
Photon Server Deep Dive - PhotonWireの実装から見つめるPhotonServerの基礎と応用 by Yoshifumi Kawai
Photon Server Deep Dive - PhotonWireの実装から見つめるPhotonServerの基礎と応用Photon Server Deep Dive - PhotonWireの実装から見つめるPhotonServerの基礎と応用
Photon Server Deep Dive - PhotonWireの実装から見つめるPhotonServerの基礎と応用
Yoshifumi Kawai52K views
Clash of Oni Online - VR Multiplay Sword Action by Yoshifumi Kawai
Clash of Oni Online - VR Multiplay Sword Action Clash of Oni Online - VR Multiplay Sword Action
Clash of Oni Online - VR Multiplay Sword Action
Yoshifumi Kawai37.6K views
History & Practices for UniRx UniRxの歴史、或いは開発(中)タイトルの用例と落とし穴の回避法 by Yoshifumi Kawai
History & Practices for UniRx UniRxの歴史、或いは開発(中)タイトルの用例と落とし穴の回避法History & Practices for UniRx UniRxの歴史、或いは開発(中)タイトルの用例と落とし穴の回避法
History & Practices for UniRx UniRxの歴史、或いは開発(中)タイトルの用例と落とし穴の回避法
Yoshifumi Kawai68K views
Introduction to NotifyPropertyChangedGenerator by Yoshifumi Kawai
Introduction to NotifyPropertyChangedGeneratorIntroduction to NotifyPropertyChangedGenerator
Introduction to NotifyPropertyChangedGenerator
Yoshifumi Kawai90.2K views

Recently uploaded

How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...Vadym Kazulkin
70 views64 slides
Five Things You SHOULD Know About Postman by
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
25 views43 slides
Microchip: CXL Use Cases and Enabling Ecosystem by
Microchip: CXL Use Cases and Enabling EcosystemMicrochip: CXL Use Cases and Enabling Ecosystem
Microchip: CXL Use Cases and Enabling EcosystemCXL Forum
129 views12 slides
Throughput by
ThroughputThroughput
ThroughputMoisés Armani Ramírez
32 views11 slides
AMD: 4th Generation EPYC CXL Demo by
AMD: 4th Generation EPYC CXL DemoAMD: 4th Generation EPYC CXL Demo
AMD: 4th Generation EPYC CXL DemoCXL Forum
126 views6 slides

Recently uploaded(20)

How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin70 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman25 views
Microchip: CXL Use Cases and Enabling Ecosystem by CXL Forum
Microchip: CXL Use Cases and Enabling EcosystemMicrochip: CXL Use Cases and Enabling Ecosystem
Microchip: CXL Use Cases and Enabling Ecosystem
CXL Forum129 views
AMD: 4th Generation EPYC CXL Demo by CXL Forum
AMD: 4th Generation EPYC CXL DemoAMD: 4th Generation EPYC CXL Demo
AMD: 4th Generation EPYC CXL Demo
CXL Forum126 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi113 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS23 views
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier29 views
Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS39 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
"How we switched to Kanban and how it integrates with product planning", Vady... by Fwdays
"How we switched to Kanban and how it integrates with product planning", Vady..."How we switched to Kanban and how it integrates with product planning", Vady...
"How we switched to Kanban and how it integrates with product planning", Vady...
Fwdays61 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS25 views
Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa... by The Digital Insurer
Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa...Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa...
Webinar : Competing for tomorrow’s leaders – How MENA insurers can win the wa...
Combining Orchestration and Choreography for a Clean Architecture by ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs168 views
"Fast Start to Building on AWS", Igor Ivaniuk by Fwdays
"Fast Start to Building on AWS", Igor Ivaniuk"Fast Start to Building on AWS", Igor Ivaniuk
"Fast Start to Building on AWS", Igor Ivaniuk
Fwdays36 views
TE Connectivity: Card Edge Interconnects by CXL Forum
TE Connectivity: Card Edge InterconnectsTE Connectivity: Card Edge Interconnects
TE Connectivity: Card Edge Interconnects
CXL Forum96 views
MemVerge: Memory Viewer Software by CXL Forum
MemVerge: Memory Viewer SoftwareMemVerge: Memory Viewer Software
MemVerge: Memory Viewer Software
CXL Forum118 views

Binary Reading in C#

  • 3. Int32 Read(byte[] bytes, int offset) { return (bytes[offset + 0] << 24) | (bytes[offset + 1] << 16) | (bytes[offset + 2] << 8) | (bytes[offset + 3]); } Int32 Read(byte[] bytes, int offset) { return (bytes[offset + 0]) | (bytes[offset + 1] << 8) | (bytes[offset + 2] << 16) | (bytes[offset + 3] << 24); } unsafe int ReadInt32(byte[] bytes, int offset) { fixed (byte* ptr = bytes) { return *(int*)(ptr + offset); } }
  • 4. [StructLayout(LayoutKind.Explicit)] internal struct Float32Bits { [FieldOffset(0)] public float Value; [FieldOffset(0)] public Byte Byte0; [FieldOffset(1)] public Byte Byte1; [FieldOffset(2)] public Byte Byte2; [FieldOffset(3)] public Byte Byte3; }
  • 6. public MessagepackType ReadMessagePackType(byte[] bytes, int offset) { var code = bytes[offset]; if (0 <= code && code <= MessagePackRange.MaxFixPositiveInt) { return FixInt; } if (MessagePackRange.MinFixNegativeInt <= code) { return NegativeInt; } switch (code) { case Int8: return Int8; case Int16: return Int16; case Int32: return Int32; // 以下略 }
  • 7. static readonly MessagePackType[] typeLookupTable = new MessagePackType[256]; static MessagePackCode() { for (int i = MinFixInt; i <= MaxFixInt; i++) { typeLookupTable[i] = MessagePackType.Integer; } for (int i = MinFixMap; i <= MaxFixMap; i++) { typeLookupTable[i] = MessagePackType.Map; } typeLookupTable[Nil] = MessagePackType.Nil; typeLookupTable[False] = MessagePackType.Boolean; typeLookupTable[True] = MessagePackType.Boolean; typeLookupTable[Bin8] = MessagePackType.Binary; typeLookupTable[Bin16] = MessagePackType.Binary; // 以下略.... }
  • 8. static readonly IMapHeaderDecoder[] mapHeaderDecoders = new IMapHeaderDecoder[MaxSize]; static readonly IArrayHeaderDecoder[] arrayHeaderDecoders = new IArrayHeaderDecoder[MaxSize]; static readonly IBooleanDecoder[] booleanDecoders = new IBooleanDecoder[MaxSize]; static readonly IByteDecoder[] byteDecoders = new IByteDecoder[MaxSize]; static readonly IBytesDecoder[] bytesDecoders = new IBytesDecoder[MaxSize]; static readonly ISByteDecoder[] sbyteDecoders = new ISByteDecoder[MaxSize]; static readonly ISingleDecoder[] singleDecoders = new ISingleDecoder[MaxSize]; static readonly IDoubleDecoder[] doubleDecoders = new IDoubleDecoder[MaxSize]; static readonly IInt16Decoder[] int16Decoders = new IInt16Decoder[MaxSize]; static readonly IInt32Decoder[] int32Decoders = new IInt32Decoder[MaxSize]; static readonly IInt64Decoder[] int64Decoders = new IInt64Decoder[MaxSize]; static readonly IUInt16Decoder[] uint16Decoders = new IUInt16Decoder[MaxSize]; static readonly IUInt32Decoder[] uint32Decoders = new IUInt32Decoder[MaxSize]; static readonly IUInt64Decoder[] uint64Decoders = new IUInt64Decoder[MaxSize]; static readonly IStringDecoder[] stringDecoders = new IStringDecoder[MaxSize]; static readonly IExtDecoder[] extDecoders = new IExtDecoder[MaxSize]; static readonly IExtHeaderDecoder[] extHeaderDecoders = new IExtHeaderDecoder[MaxSize]; static readonly IDateTimeDecoder[] dateTimeDecoders = new IDateTimeDecoder[MaxSize]; static readonly IReadNextDecoder[] readNextDecoders = new IReadNextDecoder[MaxSize];
  • 9. static readonly IMapHeaderDecoder[] mapHeaderDecoders = new IMapHeaderDecoder[MaxSize]; static readonly IArrayHeaderDecoder[] arrayHeaderDecoders = new IArrayHeaderDecoder[MaxSize]; static readonly IBooleanDecoder[] booleanDecoders = new IBooleanDecoder[MaxSize]; static readonly IByteDecoder[] byteDecoders = new IByteDecoder[MaxSize]; static readonly IBytesDecoder[] bytesDecoders = new IBytesDecoder[MaxSize]; static readonly ISByteDecoder[] sbyteDecoders = new ISByteDecoder[MaxSize]; static readonly ISingleDecoder[] singleDecoders = new ISingleDecoder[MaxSize]; static readonly IDoubleDecoder[] doubleDecoders = new IDoubleDecoder[MaxSize]; static readonly IInt16Decoder[] int16Decoders = new IInt16Decoder[MaxSize]; static readonly IInt32Decoder[] int32Decoders = new IInt32Decoder[MaxSize]; static readonly IInt64Decoder[] int64Decoders = new IInt64Decoder[MaxSize]; static readonly IUInt16Decoder[] uint16Decoders = new IUInt16Decoder[MaxSize]; static readonly IUInt32Decoder[] uint32Decoders = new IUInt32Decoder[MaxSize]; static readonly IUInt64Decoder[] uint64Decoders = new IUInt64Decoder[MaxSize]; static readonly IStringDecoder[] stringDecoders = new IStringDecoder[MaxSize]; static readonly IExtDecoder[] extDecoders = new IExtDecoder[MaxSize]; static readonly IExtHeaderDecoder[] extHeaderDecoders = new IExtHeaderDecoder[MaxSize]; static readonly IDateTimeDecoder[] dateTimeDecoders = new IDateTimeDecoder[MaxSize]; static readonly IReadNextDecoder[] readNextDecoders = new IReadNextDecoder[MaxSize]; internal interface IInt32Decoder { Int32 Read(byte[] bytes, int offset, out int readSize); }
  • 11. void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
  • 12. byte[] WriteVector3(Vector3[] collection) { var bytes = new byte[collection.Length * 12]; foreach (var item in collection) { WriteFloat(bytes, item.x); WriteFloat(bytes, item.y); WriteFloat(bytes, item.z); } return bytes; }
  • 14. public static unsafe void SimpleMemoryCopy(void* dest, void* src, int byteCount) { var pDest = (byte*)dest; var pSrc = (byte*)src; for (int i = 0; i < byteCount; i++) { *pDest = *pSrc; pDest++; pSrc++; } }