Skip to content

Instantly share code, notes, and snippets.

View yfakariya's full-sized avatar
🎯
Focusing

Yusuke Fujiwara yfakariya

🎯
Focusing
View GitHub Profile
@yfakariya
yfakariya / ProtoBufCompatIdea.cs
Created August 5, 2012 13:40
An idea to resolve incompatibility of DataMemberAttribute.Order's lower bound between msgpack and protobuf.
// Initialize SerializationContext, which can be singleton.
var context = new SerializationContext();
// Set compatibility option, which set array lower bounds to 1 instead of 0.
context.CompatibilityOptions.OneDataMemberLowerBound = true;
// Following is as is...
var serializer = MessagePackSerializer.Create<Foo>( context );
using( var stream = new MemoryStream() )
{
@yfakariya
yfakariya / New_MsgPack-CLI_String_draft.md
Last active December 14, 2015 03:39
A draft of MsgPack-CLI new string implementation related to issue121 of msgpack.

About String

As of new MessagePack specification, MessagePack specified Unicode string handling. This document describes MsgPack-CLI design and implementation for it.

Current Design

Previously, the defacto-standard interpretation of MessagePack specification is Unicode string should be encoded UTF-8 without BOM and stores as Raw type. So, MsgPack-CLI is implemented as following:

  • Packer packs String (or Char sequence) as UTF-8 bytes on Raw type. Note that Packer provides overloaded methods which accepts System.Text.Encoding to specify custom character encoding.
  • Unpacker and MessagePackObject handles Raw type value as Byte[], and they provides ReadString or AsString method which handles character decoding from unpacked Raw type value.
  • MessagePackSerializer uses above primitive API as following rules:
@yfakariya
yfakariya / gist:64cbd15868f78604ef86
Created January 11, 2015 13:33
Visual Studio のプロジェクト追加ダイアログの既定の言語を変更する方法

意外とわからなかったのでメモ。

最近の Visual Studio(少なくとも 2013)で、ソリューションに新しいプロジェクトを追加するときなどの既定の言語を変える方法。 この設定は [オプション] メニューなど GUI から直接変更することはできず、[設定のインポートとエクスポート] を使用して設定を変更する必要がある。具体的には、「Environment_NewProjectDialogPreferredLanguage」という名前のカテゴリの「NewProjectDialogPreferredLanguage」と「HasNewProjectDialogPreferredLanguage」というプロパティを設定する必要がある。

手順としては以下のような感じ。

  1. 追加したい言語の既定の設定から、「NewProjectDialogPreferredLanguage」を調べる。具体的には、%Program Files(x86)%Microsoft Visual Studio 12.0\Common7\IDE\Profiles\ の下にある、好きな言語の設定をテキストエディタで調べて、「」で検索してその値をメモっておく。
  2. [ツール] の [設定のインポートとエクスポート]を使って、現在の設定を好きな場所にエクスポートする。既定では %UserProfile%\Documents\Visual Studio 2013\Settings とかにはかれる。
  3. 出力したファイルをテキストエディタで開いて、で検索。その値が false になっていたら true に変える(「全般的な開発設定」とかでインストールしていると false になっている)
@yfakariya
yfakariya / gist:fb6d5c66fa4d8a82346b
Last active September 4, 2015 11:27
Spec draft for embedding type information

Purpose 目的

Make .NET to .NET serialization more easily by embedding type information. Interoperability should be considered as possible. 型情報を埋め込むことで、.NET どうしのシリアライズをもっと楽にする。相互運用性は可能な限り考慮されるべき。

Usecase ユースケース

  1. Serialize polimorphic collection (issue #58) ポリモーフィックなコレクションをシリアライズする
  2. Serialize 'rich' domain model which has own data and logic (issue #47)
@yfakariya
yfakariya / IsNull.cs
Created October 28, 2015 14:24
IsNull revised
using System;
static class Program
{
static void Main()
{
Test( "a" );
Test( 1 );
Test<int?>( 1 );
}

.NET Coreコードリーディングことはじめ

このエントリはWindows & Microsoft技術 基礎 Advent Calendar 2015の6日目です。

.NETのトラブルシュートをしたり、実装に興味があったり、日々の仕事に疲れた心への癒やしとして、.NETの実装を見たいことがあると思います。このエントリでは、そういった方向けに簡単なガイドを提供します。

前提と対象

.NETの実装は色々あるのですが、この記事では.NET 5向けの実装についての話をします。それ以前のMicrosoft実装については、クラスライブラリ部分のみリファレンスソースとして公開されているので、そちらを参照すると良いでしょう(ランタイムそのもののソースコードは公開されていません)。ライセンスもMITライセンスなので安心です。ただし、クライアント側(Windows FormsやWPF)のコードはgithubには公開されておらず、Microsoftのサイトで公開されており、そのライセンスはMicrosoft Reference Source Licenseとなっていますので、デバッグや相互運用性の向上を目的としない使用には注意が必要です。XamarinやUnityで使っているMonoについては、素直にMonoのソースツリーを見ればいいでしょう。ただし、クラスライブラリはMITライセンスですが、ランタイムはLGPLなので、人によっては注意が必要かもしれません。

@yfakariya
yfakariya / ReactiveProperty_NetStandard.json
Created July 9, 2016 06:58
ReactivePropertyのproject.json書いてみた
// 本体のほう
{
"version": "1.0.0-*",
"dependencies": {
"System.Runtime": "4.1.0",
"System.Collections": "4.0.11",
"System.ObjectModel": "4.0.12",
"System.Reflection": "4.1.0",
"System.Reflection.Extensions": "4.0.1",
@yfakariya
yfakariya / UnifiedResponse.cs
Created August 13, 2016 07:33
PoC code (not tested) to unify view as HTML response and web API response
// Copyright(c) 2016 FUJIWARA, Yusuke
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@yfakariya
yfakariya / NoteOfImplementationOfCSharp7_8_ja.md
Created May 3, 2019 12:32
C#7やC#8の新機能の実装についてのメモ。実装とは、ILなりメタデータの表現のことを指す。

ジェネリック型パラメーターのenum制約

  • 型パラメーターの制約に System.Enum 型があるだけ
  • struct 制約は付かない。

ジェネリック型パラメーターのunmanaged制約

  • 型パラメーターにカスタム属性 System.Runtime.CompilerServices.IsUnamagedAttribute が適用されているかどうか。なお、拡張メソッドと同じく、属性の型のアセンブリ名は無視される。C# 8 previewコンパイラーは、この属性をコンパイル結果のアセンブリに生成している。
  • 型パラメーターに modreq として System.Runtime.InteropServices.UnmanagedType が指定されている。
  • struct 制約も同時に付く。
@yfakariya
yfakariya / iotedge-deep-dive-1_edgelet.md
Last active November 29, 2021 15:48
IoT Edge Deep Dive (ja) -- notes of Azure IoT Edge source code readings. See https://github.com/azure/iotedge for original source code (MIT License).

IoT Edge Deep Dive 1 -- Edgelet

IoT Edgeの中で、ホスト(つまりDockerコンテナーの外側)で動作するコンポーネントとして、IoT Edgeセキュアデーモン(iotedged)とCLI(iotedge)がある。 これらはedgeletと呼ばれるネイティブコンポーネントで動作する(ちなみに、edgeletのほとんどはRustで記述されている。HSMと直接通信する部分のみC言語で記述されている)。

IoT Edgeセキュアデーモンは、以下の役割を持つコンポーネントである。

  • HSM(Hardware Security Module)を抽象化する
  • Dockerコンテナー内で動作するIoT Edgeのモジュールに対して、モジュールのアイデンティティに関わる情報のストレージを提供する