@ -1,5 +1,5 @@
#region Copyright notice and license
#region Copyright notice and license
// Copyright 2015, Google Inc.
// Copyright 2015-2016 , Google Inc.
// All rights reserved.
// All rights reserved.
/ /
/ /
// Redistribution and use in source and binary forms, with or without
// Redistribution and use in source and binary forms, with or without
@ -179,7 +179,7 @@ namespace Grpc.Core
private void CheckWriteable ( )
private void CheckWriteable ( )
{
{
Preconditions . CheckState ( ! readOnly , "Object is read only" ) ;
Grpc Preconditions. CheckState ( ! readOnly , "Object is read only" ) ;
}
}
# endregion
# endregion
@ -211,10 +211,10 @@ namespace Grpc.Core
public Entry ( string key , byte [ ] valueBytes )
public Entry ( string key , byte [ ] valueBytes )
{
{
this . key = NormalizeKey ( key ) ;
this . key = NormalizeKey ( key ) ;
Preconditions . CheckArgument ( this . key . EndsWith ( BinaryHeaderSuffix ) ,
Grpc Preconditions. CheckArgument ( this . key . EndsWith ( BinaryHeaderSuffix ) ,
"Key for binary valued metadata entry needs to have suffix indicating binary value." ) ;
"Key for binary valued metadata entry needs to have suffix indicating binary value." ) ;
this . value = null ;
this . value = null ;
Preconditions . CheckNotNull ( valueBytes , "valueBytes" ) ;
Grpc Preconditions. CheckNotNull ( valueBytes , "valueBytes" ) ;
this . valueBytes = new byte [ valueBytes . Length ] ;
this . valueBytes = new byte [ valueBytes . Length ] ;
Buffer . BlockCopy ( valueBytes , 0 , this . valueBytes , 0 , valueBytes . Length ) ; // defensive copy to guarantee immutability
Buffer . BlockCopy ( valueBytes , 0 , this . valueBytes , 0 , valueBytes . Length ) ; // defensive copy to guarantee immutability
}
}
@ -227,9 +227,9 @@ namespace Grpc.Core
public Entry ( string key , string value )
public Entry ( string key , string value )
{
{
this . key = NormalizeKey ( key ) ;
this . key = NormalizeKey ( key ) ;
Preconditions . CheckArgument ( ! this . key . EndsWith ( BinaryHeaderSuffix ) ,
Grpc Preconditions. CheckArgument ( ! this . key . EndsWith ( BinaryHeaderSuffix ) ,
"Key for ASCII valued metadata entry cannot have suffix indicating binary value." ) ;
"Key for ASCII valued metadata entry cannot have suffix indicating binary value." ) ;
this . value = Preconditions . CheckNotNull ( value , "value" ) ;
this . value = Grpc Preconditions. CheckNotNull ( value , "value" ) ;
this . valueBytes = null ;
this . valueBytes = null ;
}
}
@ -270,7 +270,7 @@ namespace Grpc.Core
{
{
get
get
{
{
Preconditions . CheckState ( ! IsBinary , "Cannot access string value of a binary metadata entry" ) ;
Grpc Preconditions. CheckState ( ! IsBinary , "Cannot access string value of a binary metadata entry" ) ;
return value ? ? Encoding . GetString ( valueBytes ) ;
return value ? ? Encoding . GetString ( valueBytes ) ;
}
}
}
}
@ -323,8 +323,8 @@ namespace Grpc.Core
private static string NormalizeKey ( string key )
private static string NormalizeKey ( string key )
{
{
var normalized = Preconditions . CheckNotNull ( key , "key" ) . ToLower ( CultureInfo . InvariantCulture ) ;
var normalized = Grpc Preconditions. CheckNotNull ( key , "key" ) . ToLower ( CultureInfo . InvariantCulture ) ;
Preconditions . CheckArgument ( ValidKeyRegex . IsMatch ( normalized ) ,
Grpc Preconditions. CheckArgument ( ValidKeyRegex . IsMatch ( normalized ) ,
"Metadata entry key not valid. Keys can only contain lowercase alphanumeric characters, underscores and hyphens." ) ;
"Metadata entry key not valid. Keys can only contain lowercase alphanumeric characters, underscores and hyphens." ) ;
return normalized ;
return normalized ;
}
}